<template>
	<view class="my_content">
		<view class="userifon_contet">
			<u-navbar :custom-back="Navigateback" :back-icon-color="'#fff'" :border-bottom="false" :back-text-style="{color:'#fff'}" :title-color="'#ffffff'" back-text="返回" title="商户中心" :background="{ background: '#ffffff00' }"></u-navbar>
			<view class="userifon">
				<view class="us_img">
					<!-- <image :src="userInfo.avatar" mode="widthFix"></image> -->
					<image src="/static/my/mr.png" mode=""></image>
				</view>
				<view class="right">
					<view class="us_name">{{userInfo.shopName}}服务中心</view>
					<!-- <view class="dy">{{userInfo.shopName}}服务中心</view> -->
					<view class="id">
					<image src="https://img.shihhl.com/shequ/mobile.png" mode="widthFix"></image>
					{{userInfo.phone}}</view>
				</view>
			</view>
			<view class="sculpture">
				<view class="sculpture_itme">
					<view class="sum">{{userdata.couponCount}}</view>
					<view class="name">优惠券核销</view>
				</view>
				<view class="sculpture_itme">
					<view class="sum">{{userdata.creditOrderCount}}</view>
					<view class="name">积分订单核销</view>
				</view>
				<view class="sculpture_itme">
					<view class="sum">{{userdata.employeeCount}}</view>
					<view class="name">员工卡核销</view>
				</view>
			</view>
			<view class="manglis">
				<view class="mag_itme" @click="GetNav(0)">
					 <view class="title">
						 <image src="/static/my/money.png" mode="widthFix"></image>
						 <view>今日核销优惠券</view>
					 </view>
					 <view class="sum">{{userdata.couponCountToday}}</view>
					 <view class="zr">
						 <view>昨日数据</view>
						 <view>{{userdata.couponCountYesterday}}</view>
					 </view>
				</view>
				<view class="mag_itme" @click="GetNav(1)">
					 <view class="title">
						 <image src="/static/my/jf.png" mode="widthFix"></image>
						 <view>今日核销积分订单</view>
					 </view>
					 <view class="sum">{{userdata.creditOrderCountToday}}</view>
					 <view class="zr">
						 <view>昨日数据</view>
						 <view>{{userdata.creditOrderCountYesterday}}</view>
					 </view>
				</view>
			</view>
		</view>
		<view class="content">
			<!-- 我的服务 -->
			<view class="service">
				<view class="title">
					商家中心
				</view>
				<view class="selce">
					<view class="selce_itme" v-for="(item,index) in selce_list" :key="index" @click="Navigator(index,item.url)">
						<image :src="'/static/my/sh'+ (index + 1) +'.png'" mode="widthFix"></image>
						<view class="name">{{item.name}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {  writeOffcount , writeOff } from '@/core/api/index.js'
	import { mapState } from 'vuex';
	export default{
		data(){
			return{
				selce_list:[
					{
						name:'扫码核销',
						url:"/pages/my/my_receipt"
					},
					{
						name:'输码核销',
						url:"/pages/merchantenter/verification"
					},
					{
						name:'核销记录',
						url: "/pages/merchantenter/record",
					},
					{
						name:'在售优惠券',
						url:"/pages/merchantenter/sale_coupons"
					},
					{
						name:'意见反馈',
						url:"/pages/merchantenter/feedback"
					},
					{
						name:'上传报表',
						url:"/pages/merchantenter/uploadreport"
					},
					{
						name:'联系客服'
					},
				],
				writeOffNo:'',
				userdata:null
			}
		},
		computed: {
		  ...mapState({
		    userInfo: state => state.user.userInfo
		  })
		},
		onLoad() {
			this.WriteOffcount()
		},
		methods:{
			GetNav(index){
				uni.navigateTo({
					url:'/pages/merchantenter/record?index=' + index
				})
			},
			async WriteOffcount(){
				const {data} = await writeOffcount()
				this.userdata = data
			},
			 Navigator(index,url){
				if(index == 0){
					uni.scanCode({
						onlyFromCamera: true,
						success: async (res)=> {
							console.log('条码类型：' + res.scanType);
							console.log('条码内容：' + res.result);
							uni.showLoading({
								title:'核销中...'
							})
							const data = await writeOff(res.result)
							console.log(data,'打印')
							if(data.code == '00000'){
								uni.showToast({
									title:'核销成功'
								})
								console.log(this)
								// uni.hideLoading()
								this.WriteOffcount()
								this.$store.dispatch('user/getUserinfo')
							}else{
								uni.showToast({
									title:data.message,
									icon:'none'
								})
							}
						}
					});
				}else{
					uni.navigateTo({
						url
					})
				}
			},
			Navigateback(){
				uni.navigateBack({
					delta:1
				})
			}
		}
	}
</script>
<style>
	page{
		background:url(https://img.shihhl.com/shequ/sj_03.png) no-repeat;
		background-size: 100%;
	}
</style>
<style lang="scss">
	::v-deep .u-navbar-inner{
	    margin-right: 0 !important;
	}
	.my_content{
		display: flex;
		// flex: 1;
		flex-direction: column;
		height: 100vh;
	}
	.userifon{
		// height: 489rpx;
		// background: var(--Color, #F26B2E);
		padding: 45rpx 30rpx 40rpx;
		display: flex;
		align-items: center;
		position: relative;
		.us_img{
			width: 108rpx;
			height: 108rpx;
			image{
				width: 100%;
				border-radius: 50%;
				height: 100%;
			}
		}
		.right{
			margin-left: 20rpx;
			color: #FFF;
			font-size: 26rpx;
            .us_name{
				font-size: 32rpx;
				margin-bottom: 10rpx;
			}
			image{
				width: 30rpx;
			    margin-right: 5rpx;
				// height: ;
			}
		}
		.id{
			display: flex;
			align-items: center;
			margin-top:10rpx;
		}
		.tb{
			position: absolute;
			    width: 92%;
			    bottom: -3%;
			// width: 100%;
			image{
				width: 100%;
				border-radius: 20rpx;
			}
		}
	}
	.sculpture{
		// padding: 0 60rpx;
		color: #fff;
		display: flex;
		.sculpture_itme{
			width: 33%;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			font-size: 24rpx;
			.sum{
				font-size: 46rpx;
				font-weight: 700;
			}
		}
	}
	.manglis{
		display: flex;
		padding: 0 30rpx;
		margin-top: 32rpx;
		justify-content: space-between;
		.mag_itme{
			padding: 26rpx 20rpx 15rpx;
			// height: 20rpx;
			width: 49%;
			border-radius: 15rpx;
			background-color: #fff;
			image{
				width: 36rpx;
				margin-right: 15rpx;
			}
			.title{
				display: flex;
				align-items: center;
				font-size: 28rpx;
			}
			.sum{
				font-weight: 600;
				font-size: 60rpx;
				padding: 50rpx 40rpx;
			}
			.zr{
				display: flex;
				justify-content: space-between;
				color: var(--, #A3A3A3);
               font-size: 24rpx;
			   padding-right: 30rpx;
			}
		}
	}
	.content{
		flex: 1;
		// background: url(https://img.shihhl.com/shequ/%E8%83%8C%E6%99%AF.png) no-repeat;
		background-size: 100%;
		    margin-top: -3%;
		    z-index: 1;
		.service{
			margin: 50rpx 30rpx;
			padding: 32rpx 0rpx 0rpx;
			border-radius: 20rpx;
			background-color: #fff;
			.title{
				position: relative;
				padding: 0 30rpx;
				font-weight: 500;
				font-size: 32rpx;
				border-radius: 10rpx;
				background-color: #FFF;
			}
			.title::after{
				content: " ";
				border-radius: 20px;
				background: var(--Color, #F26B2E);
				width: 68rpx;
				height: 8rpx;
				    bottom: -34%;
				    left: 5%;
				position: absolute;
			}
		}
		.selce{
			display: flex;
			margin-top: 50rpx;
			flex-wrap: wrap;
		}
		.selce_itme{
			width: 25%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			margin-bottom: 40rpx;
			align-items: center;
			image{
				width: 50rpx;
				margin-bottom: 10rpx;
			}
			font-size: 24rpx;
			// margin-top: 10rpx;
		}
	}
</style>